package com.example.demo.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import com.example.demo.config.HelloProperties;
import com.example.demo.pojo.Hello;
import com.example.demo.service.UserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import lombok.extern.java.Log;
@Log
@Controller
public class HelloPro {
	@Autowired
	private HelloProperties hello;
	@Autowired
	UserService userservice;
	@RequestMapping("/HellPro")
	public HelloProperties hello() {
		log.info("开始啦~"+"id："+hello.getId()+"，name："+hello.getName());
		
		return hello;
		
	}
	
	@RequestMapping(value = "")
	public String index() {
		return "cors";
	}
	
	@RequestMapping("/getAllPerson")
	public String  allUser(Model model,@RequestParam(defaultValue = "1",value = "pageNum") Integer pageNum) {
		PageHelper.startPage(pageNum,5);
		List<Hello> all=userservice.allUser();
		PageInfo<Hello> pageInfo = new PageInfo<>(all);
		model.addAttribute("pageInfo", pageInfo);
		return "hello";
		
	}
	
	@RequestMapping("/del")
	public String  delUser(Model model,@RequestParam(defaultValue = "1",value = "pageNum") Integer pageNum,String id) {
		PageHelper.startPage(pageNum,5);
		userservice.delete(id);
		
		List<Hello> all=userservice.allUser();
		PageInfo<Hello> pageInfo = new PageInfo<>(all);
		model.addAttribute("pageInfo", pageInfo);
		return "hello";
		
	}
	
	

}
